package com.tsinkai.ettp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tsinkai.ettp.common.ResultModel;
import com.tsinkai.ettp.model.Classa;
import com.tsinkai.ettp.utils.JsonUtils;
import com.tsinkai.ettp.utils.RedisOperator;

@RestController
@RequestMapping("redis")
public class RedisController {
	
	@Autowired
	private StringRedisTemplate strRedis;
	
	@Autowired
	private RedisOperator redis;
	
	@RequestMapping("test")
	public ResultModel test() {
		
		strRedis.opsForValue().set("test", "hello");
		Classa classa = new Classa();
		classa.setId(1);
		classa.setClassName("li");
		classa.setAddress("earth");
		strRedis.opsForValue().set("user", JsonUtils.objectToJson(classa));
		
		Classa c = JsonUtils.jsonToPojo(strRedis.opsForValue().get("user"), Classa.class);
		return ResultModel.ok(c);
	}
}
